<script>
    function findall(a,x) {
        var results=[];
        len=a.length;
        pos=0;
        while (pos<len) {
            pos=a.indexOf(x,pos);
            if (pos===-1) {
                break;
            }
            results.push(pos);
            pos+=1;
        }
        return results;
    }
    var arr=['a','b','d','d','c','d','d'];
    document.write(findall(arr,'d'));
    function count(arr,item) {
        var number=0;
        for (let i = 0; i <arr.length; i++) {
            if (arr[i]==item) {
                number++;
            }
        }
        return number;
    }
    document.write('</br>'+count(arr,'d'));
    
</script>